tongfusoft.notice = function() {
}

var currUserId = "";
tongfusoft.notice.prototype = {
		currUser : function(){
			common.post('currUser', {
			}, function(data) {
				if (data.state == 'success') {
					currUserId = data.data.userId;
				}
			});
		},
		docList : function(pageIndex,pageSize,query) {
			common.post('personalCenter/noticeDocs/query',{"userId":currUserId,"pageIndex":pageIndex,"pageSize":pageSize,"query":query},function(data){
				
				var docListHtml="<tr><td>"
				$.each(data.list,function(index,item){
					
		
					docListHtml=docListHtml+'<div class="media-box">';
					docListHtml=docListHtml+'<a href="#" docname="'+item.docName+'" onclick="new tongfusoft.notice().detail(this)" class="pull-left">';
					docListHtml=docListHtml+'<img src="'+common.getContextPath('img/dc/'+item.docIcon)+'" alt="" class="media-box-object img-responsive img-rounded thumb64">';
					docListHtml=docListHtml+'</a>';
					docListHtml=docListHtml+'<div class="media-box-body">';
					
					//操作按钮
					docListHtml=docListHtml+'<div class="pull-right">';
				
					docListHtml=docListHtml+'<button docName="'
														+ item.docName
														+ '" onclick="new tongfusoft.notice().detail(this)" type="button" class="btn btn-sm btn-default  icon-list detailBtn"></button>'
					docListHtml=docListHtml+'<button docName="'
														+ item.docName
														+ '" onclick="new tongfusoft.notice().del(this)" type="button" class="btn btn-sm btn-default fa fa-trash delBtn"></button>'
					docListHtml=docListHtml+'</div>';
					
					
					docListHtml=docListHtml+'<h4 class="media-box-heading">'+item.docTitle+'</h4>';
					docListHtml=docListHtml+'<small title="'+item.docSummary+'" class="text-muted">'+item.docSummary.substr(0,50)+"....." +'</small>';
					docListHtml=docListHtml+'<p>';
					
					docListHtml=docListHtml+'<em class="fa fa-user mr-sm"> </em><span class="mr">'+item.docAuthor+'</span><em class="fa fa-building mr-sm"> </em><span>'+item.lastUpdDate+'</span>';
					docListHtml=docListHtml+'<span class="mr"></span><a href="'+common.getContextPath('download/'+item.docName)+'" target="_blank" ><em class="fa fa-download mr"></em></a>';
					docListHtml=docListHtml+'</p>';
					docListHtml=docListHtml+'</div>';
					docListHtml=docListHtml+' </div>';
					
					
				});
				
				docListHtml=docListHtml+'</td></tr>';
				$("#noticeTable").html(docListHtml);
				new tongfusoft.notice().pageing(data);
			});
		},
		//分页
		pageing:function(data){
			
			$('#noticePage').jqPaginator({
			    totalPages: data.pages==0?1:data.pages,
			    visiblePages: 5,
			    currentPage: 1,
			    pageSize:data.pageSize,
			    first: '',
		        prev: '<li class="prev"><a href="javascript:;">上一页</a></li>',
		        next: '<li class="next"><a href="javascript:;">下一页</a></li>',
		        last: '',
		        page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
			    onPageChange: function (num, type) {
			    	if(type=='change')
			    		new tongfusoft.notice().docList(num,data.pageSize);
			    }
			});
		},
		//查询
		search : function(){
			$("#searchBtn").click(function(){
				$("#queryText").val(JSON.stringify({"fastText":$("#searchText").val()}));
				new tongfusoft.notice().docList(1,10,$("#queryText").val());
				
			});
		},
		//详情
		detail : function(obj){
			window.location.href=common.getContextPath('docView/myNotice/'+$(obj).attr("docName"));
		},
		//删除
		del : function(obj){
			swal({
				title : "是否确认?",
				text : "",
				type : "warning",
				showCancelButton : true,
				confirmButtonColor : "#DD6B55",
				confirmButtonText : "删除",
				cancelButtonText : "取消",
				closeOnConfirm : true
			}, function() {
				common.ajaxSubmitOnSuccess({
					"userId" : currUserId,
					"docName": $(obj).attr("docName")
				}, 'personalCenter/notice/del', function(data) {

					if (data.state == 'success') {

						new tongfusoft.notice().docList(1,2);
						new tongfusoft.header().notice(1,2);
					} else{
						toastr["error"]('删除失败!');
					}

				}, "del")
			});
		}
}

$(function(){
	var obj= new tongfusoft.notice();
	obj.currUser();
	obj.docList(1,10,'');
	obj.search();
})